<div class="page-header">
    <h3><?php echo lang('events_admin'); ?></h3>
</div>

<?php
if(!isset($events)):
echo '<p class="alert">'.lang('no_events_created').' '.anchor('events/edit', lang('event_create')).'</p>';
else:
?>

<table id="events" class="table table-condensed">
    <thead>
        <tr>
            <th><?php echo lang('creation_date'); ?></th>
            <th><?php echo lang('last_update'); ?></th>
            <th><?php echo lang('title'); ?></th>
            <th><?php echo nbs(); ?></th>
            <th><?php echo nbs(); ?></th>
        </tr>
    </thead>
    <tbody class="well">
        <?php foreach($events as $event_id => $event): ?>
        <tr>
            <td class="none"><?php echo $event_id; ?></td>
            <td><?php echo $event['creation_date'].' '.$event['creation_time']; ?></td>
            <td><?php echo $event['updated'] ? $event['last_update_date'].' '.$event['last_update_time'] : ''; ?></td>
            <td><?php echo anchor('events/view/'.$event_id, $event['title']); ?></td>
            <td>
                <div class="btn-group">
                    <?php echo anchor('#', lang('link').' <span class="caret">'.nbs().'</span>', 'class="btn dropdown-toggle" data-toggle="dropdown"'); ?>
                    <ul class="dropdown-menu">
                        <?php
                        if(isset($classes))
                            foreach($classes as $class => $events_for_class)
                                if(!in_array($event_id, array_keys($events_for_class)))
                                    echo '<li>'.anchor('events/link/'.$class.'/'.$event_id, $class, 'class="event-link"').'</li>';
                        ?>
                    </ul>
                </div>
            </td>
            <td>
                <div class="btn-group">
                    <?php
                    echo
                    anchor('events/edit/'.$event_id, lang('edit'), 'class="btn event-edit"').
                    anchor('events/delete/'.$event_id, lang('delete'), 'class="btn btn-danger event-delete"');
                    ?>
                </div>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>

<p class="event-create"><?php echo anchor('events/edit', lang('event_create')); ?></p>

<?php
endif;
?>

<hr />

<?php
if(!isset($classes)):
echo '<p class="alert">'.lang('no_classes').'</p>';
else:
?>

<div class="tabbable">
    <ul class="nav nav-pills">
        <?php
        reset($classes);
        $pill_active = key($classes);
        foreach(array_keys($classes) as $class)
            echo '<li class="'.(($class === $pill_active) ? 'active' : '').'"><a href="#'.$class.'" data-toggle="tab">'.$class.'</a></li>';
        ?>
    </ul>
    <div class="tab-content">
        <?php
        foreach($classes as $class => $events_for_class) {
            echo '<div class="tab-pane '.(($class === $pill_active) ? 'active' : '').'" id="'.$class.'">';
            if(empty($events_for_class)):
            echo '<p class="events-for-class alert">'.lang('no_events_for_class').'</p>';
            else:
            ?>
            <table class="events-for-class table table-condensed">
                <thead>
                    <tr>
                        <th><?php echo lang('publish_date'); ?></th>
                        <th><?php echo lang('title'); ?></th>
                        <th><?php echo nbs(); ?></th>
                    </tr>
                </thead>
                <tbody class="well">
                    <?php
                    foreach($events_for_class as $event_id => $event):
                    ?>
                    <tr>
                        <td class="none"><?php echo $event_id; ?></td>
                        <td><?php echo $event['published'] ? $event['publish_date'].' '.$event['publish_time'] : ''; ?></td>
                        <td><?php echo $event['title']; ?></td>
                        <td>
                            <div class="btn-group">
                                <?php
                                if($event['published'])
                                    echo anchor('events/mask/'.$class.'/'.$event_id, lang('mask'), 'class="btn event-mask"');
                                else
                                    echo anchor('events/show/'.$class.'/'.$event_id, lang('show'), 'class="btn event-show"');
                                echo anchor('events/unlink/'.$class.'/'.$event_id, lang('unlink'), 'class="btn event-unlink"');
                                ?>
                            </div>
                        </td>
                    </tr>
                    <?php
                    endforeach;
                    ?>
                </tbody>
            </table>
            <?php
            endif;
            echo '</div>';
        }
        ?>
    </div>
</div>
<?php
endif;